﻿#ifndef TCPCLIENT_H
#define TCPCLIENT_H

#include <QObject>
#include <QTcpSocket>
#include <dbHelper.h>
#include <QThread>
#include <QDebug>
#include <QHostAddress>
#include <CommonHelper.h>
#include <dbHelper.h>
#include <loghelper.h>
#include <intListener.h>
//该对象最终运行在次线程中
class TcpClient : public QTcpSocket
{
    Q_OBJECT
public:
    static TcpClient* getInstance();
    TcpClient(QObject *parent = NULL);
    ~TcpClient();
public:
    void ClientConnectToHost(const QString &address, quint16 port);
    void ClientSendingData(const QByteArray &c_btaData);
    bool IsOnline();

signals:
    //转换来自主线程的链接操作
    void SignalConnectToHost(const QString & address, quint16 port);
signals:
    //转换来自主线程的发送操作
    void SignalSendingData(const QByteArray c_btaData);
signals:
    //在次线程中缓冲并滑动解析TCP流后/按约定格式再发布
    void SignalPublishFormatRecvData(const QString c_btaData);
private slots:
    void onTimeout();

private:
    //标记连接情况
    bool m_bOnLine = false;
    static TcpClient* Instance ;
    CommonHelper* common;
    loghelper * logClient;
    QThread thread;
    QMap<QString, QString> *mapGZ;
    QString tempString;
    QString sendTitle;
};


#endif // TCPCLIENT_H
